#include "stdafx.h"
#include "vol_user_app_info.h"

bool CVolRegex::Search(const CVolString& target, const CVolString& regex, std::regex_constants::syntax_option_type syntax_type, std::regex_constants::match_flag_type flag)
{
	m_target.SetText(target.GetText());
	try {
		rx = std::wregex(regex.GetText(), syntax_type);
	} catch (std::regex_error& e) {
		return false;
	}
	return std::regex_search(m_target.GetText(), m_wcmatch, rx, flag);
}

bool CVolRegex::SearchNext(std::regex_constants::match_flag_type flag)
{
	return std::regex_search(m_wcmatch[0].second, m_wcmatch, rx, flag);
}

bool CVolRegex::Match(const CVolString& target, const CVolString& regex, std::regex_constants::syntax_option_type syntax_type, std::regex_constants::match_flag_type flag)
{
	std::wregex rx;
	m_target.SetText(target.GetText());
	try {
	    rx = std::wregex(regex.GetText(), syntax_type);
	} catch (std::regex_error& e) {
		return false;
	}
	return std::regex_match(m_target.GetText(), rx, flag);
}

std::wstring CVolRegex::Replace(const CVolString& target, const CVolString& regex, const CVolString& fmt, std::regex_constants::syntax_option_type syntax_type, std::regex_constants::match_flag_type flag)
{
	std::wregex rx;
	m_target.SetText(target.GetText());
	try {
		rx = std::wregex(regex.GetText(), syntax_type);
	} catch (std::regex_error& e) {
		return std::wstring ();
	}
	return std::regex_replace(m_target.GetText(), rx, fmt.GetText(), flag);
}